# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-childprocess
pkgver=4.1.0
pkgrel=1
pkgdesc='Cross-platform Ruby library for managing child processes'
arch=(any)
url='https://github.com/enkessler/childprocess'
license=(MIT)
depends=(ruby)
makedepends=(ruby-rspec ruby-yard)
options=(!emptydirs)
source=(https://github.com/enkessler/childprocess/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('ea7229caffcc7f2f58f304c284d8c5e28f94c8c894e6e46db15e015b358d3ce2')

prepare() {
  cd childprocess-$pkgver
  sed -r -e '/[cC]overalls/d' -e 's|git ls-files -- spec/\*|echo|' -i childprocess.gemspec spec/spec_helper.rb
  sed 's|git ls-files|find -type f|' -i childprocess.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd childprocess-$pkgver
  gem build childprocess.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    childprocess-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd childprocess-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rspec
}

package() {
  cd childprocess-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
